"""
This is to set environment variables in the LiveOcean system
using values in a csv file.  It is similar to Lstart.m in the
MATLAB code, but it returns a dictionary instead of a structure.

"""

def Lstart(path_to_alpha):
    
    import pandas as pd
    inframe = pd.read_csv(path_to_alpha + '/RUN_INFO.csv', index_col='ITEMS')
    # put the results in a dict
    Ldir = {'gridname': inframe.ix['GRIDNAME', 'VALUES']}
    Ldir['tag'] = inframe.ix['TAG', 'VALUES']
    Ldir['gtag'] = Ldir['gridname'] + '_' + Ldir['tag']
    
    # try getting some things this way, and hopefuly it will work even
    # when called by cron
    import os
    which_home = os.environ.get("HOME")
    if which_home == '/Users/PM3': # mac version
        Ldir['parent'] = '/Users/PM3/Documents/'
        Ldir['which_matlab'] = '/Applications/MATLAB_R2013a.app/bin/matlab'
    elif which_home == '/home/parker': # fjord version
        Ldir['parent'] = '/data1/parker/'
        Ldir['which_matlab'] = '/usr/local/bin/matlab'
    else:
        print 'Trouble filling out environment variables in Ldir'
    
    # and add a few more things
    Ldir['home'] = Ldir['parent'] + 'LiveOcean/'
    Ldir['res'] = Ldir['home'] + 'preamble/make_resources/'
    Ldir['out'] = Ldir['parent'] + 'LiveOcean_output/'
       
    return Ldir

    # you would get a listing of one of these directories with a call like
    # import os
    # os.listdir(Ldir['out'])





    


    

